<?php
/* --------------------------------------------------------------
   GMTSWidget.php 2011-06-10 gm
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2011 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
 */
	class GMTSWidget
	{
		/*
		*	actual used languages id
		*	@var int
		*/
		var $coo_languages_id;

		/*
		*	trusted shops id
		*	@var String
		*/
		var $coo_ts_id;

		/*
		*	trusted shops name
		*	@var String
		*/
		var $coo_ts_shop_name;

		/*
		*	trusted shops widget url
		*	@var String
		*/
		var $coo_ts_widget = 'https://www.trustedshops.com/bewertung/widget/widgets/';

		/*
		*	trusted shops info html code
		*	@var array
		*/
		var $coo_ts_info_link = array(
			1 => '<a href="https://www.trustedshops.com/buyerfeedback/signin.html?partnerPackage={#TS_ONLINESHOP#}" target="_blank" title="" rel="nofollow"></a>',
			2 => '<a href="https://www.trustedshops.com/bewertung/anmeldung.html?partnerPackage={#TS_ONLINESHOP#}" target="_blank" title="" rel="nofollow"></a>'
		);

		/*
		*	trusted shops rating html code
		*	@var array
		*/
		var $coo_ts_rating_link = array(
			1 => '<a href="https://www.trustedshops.com/buyerrating/rate_{#TS_ID#}.html&buyerEmail={#TS_BUYER_EMAIL#}&shopOrderID={#TS_ORDER_ID#}" target="_blank" title="Write a review!" rel="nofollow"><img src="{#TS_RATING_IMAGE#}images/trusted_bewerten_en.gif" alt="Write a review!" border="0" /></a>',
			2 => '<a href="https://www.trustedshops.com/bewertung/seite/bewerten_{#TS_ID#}.html&buyerEmail={#TS_BUYER_EMAIL#}&shopOrderID={#TS_ORDER_ID#}" target="_blank" title="Bewerten Sie unseren Shop!" rel="nofollow"><img src="{#TS_RATING_IMAGE#}images/trusted_bewerten_de.gif" alt="Bewerten Sie unseren Shop!" border="0" /></a>'
		);

		/*
		*	trusted shops profile html code
		*	@var array
		*	1 english
		*	2 german
		*/
		var $coo_ts_profile_link = array(
			1 => '<a target="_blank" href="https://www.trustedshops.com/buyerrating/info_{#TS_ID#}.html" title="Rating Profile {#TS_SHOP_NAME#}" rel="nofollow"><img class="bewertung" alt="Rating Profile {#TS_SHOP_NAME#}" border="0" src="{#TS_IMAGE#}" /></a>',
			2 => '<a target="_blank" href="https://www.trustedshops.com/bewertung/seite/info_{#TS_ID#}.html" title="Kundenbewertungen von {#TS_SHOP_NAME#} einsehen" rel="nofollow"><img class="bewertung" alt="Kundenbewertungen von {#TS_SHOP_NAME#} einsehen" border="0" src="{#TS_IMAGE#}" /></a>'
		);

		/*
		*	constructor
		*	@param	int $p_languages_id
		*/
		function GMTSWidget($p_languages_id)
		{
			$this->coo_languages_id	= (int)$p_languages_id;
			$this->coo_ts_id		= gm_get_content('GM_TRUSTED_SHOPS_WIDGET_SHOP_ID',		$this->coo_languages_id);
			$this->coo_ts_shop_name	= gm_get_content('GM_TRUSTED_SHOPS_WIDGET_SHOP_NAME',	$this->coo_languages_id);
			return;
		}

		/*
		*	function to get the rating link
		*	@return	String
		*/
		function get_info_link()
		{

		}

		/*
		*	function to get the rating link
		*	@param	int		$p_order_id
		*	@param	String	$p_area			(confirmation / checkout)
		*	@return	String
		*/
		function get_rating_link($p_order_id, $p_area)
		{
			if(gm_get_content($p_area, $this->coo_languages_id) == '1' && gm_get_content('GM_TRUSTED_SHOPS_WIDGET_USE', $this->coo_languages_id) == '1')
			{
				$t_ts_link			= $this->coo_ts_rating_link[$this->coo_languages_id];

				/* get customers email adress */
				$gm_ts_query = xtc_db_query("
					SELECT
						customers_email_address
					AS
						mail
					FROM " .
						TABLE_ORDERS . "
					WHERE
						orders_id = '" . $p_order_id . "'"
				);

				$gm_ts_query_data = xtc_db_fetch_array($gm_ts_query);

				/*	create trusted shops rating html code */
				if($p_area == 'GM_TRUSTED_SHOPS_WIDGET_SHOW_CONFIRMATION')
				{
					$t_ts_link = str_replace('{#TS_RATING_IMAGE#}',	HTTP_SERVER . DIR_WS_CATALOG,		$t_ts_link);
				}
				else
				{
					$t_ts_link = str_replace('{#TS_RATING_IMAGE#}',	'',													$t_ts_link);
				}

				$t_ts_link = str_replace('{#TS_ID#}',			$this->coo_ts_id,										$t_ts_link);
				$t_ts_link = str_replace('{#TS_BUYER_EMAIL#}',	urlencode(base64_encode($gm_ts_query_data['mail'])),	$t_ts_link);
				$t_ts_link = str_replace('{#TS_ORDER_ID#}',		urlencode(base64_encode($p_order_id)),					$t_ts_link);

				return $t_ts_link;
			}
		}

		/*
		*	function to get the profile link
		*	@return String
		*/
		function get_profile_link()
		{
			$t_ts_link			= $this->coo_ts_profile_link[$this->coo_languages_id];

			/*	create trusted shops profile html code */
			$t_ts_link = str_replace('{#TS_ID#}',			$this->coo_ts_id,				$t_ts_link);
			$t_ts_link = str_replace('{#TS_IMAGE#}',		$this->coo_ts_widget . $this->coo_ts_id . ".gif", $t_ts_link);
			$t_ts_link = str_replace('{#TS_SHOP_NAME#}',	$this->coo_ts_shop_name,		$t_ts_link);

			return $t_ts_link;
		}
	}

?>